// import SpyService from './service';
import log from 'electron-log';
import puppeteer, { HTTPResponse } from 'puppeteer';
import SpyConfig from './config';
import WXLiveEventHandler from './interface';
// import WXDataDecoder from './WXDataDecoder';

class WXLiveEventListener {
  private config: SpyConfig;

  // private eventHandler: WXLiveEventHandler;

  constructor(config: SpyConfig, handler: WXLiveEventHandler) {
    this.config = config;
    // this.eventHandler = handler;
  }

  // private static getContentType(response: HTTPResponse): string {
  //   const contentType = response.headers()['content-type'];
  //   if (!contentType) {
  //     return '';
  //   }
  //   // remove charset
  //   return contentType.replace(/;.*$/, '');
  // }

  public async start() {
    // log.info(`start listener on ${this.config.getProp('spy_url')}`);

    const windowSize = '--window-size=1024,1024';

    const options = {
      defaultViewport: null,
      headless: false,
      args: ['--disable-setuid-sandbox', windowSize, '--hide-crash-restore-bubble', '--disable-gpu'],
      executablePath: this.config.getProp('chrome_path'),
      ignoreHTTPSErrors: true,
      userDataDir: this.config.getProp('chrome_userdata_path'),
    };

    const browser = await puppeteer.launch(options);
    const page = await browser.newPage();
    browser.on('disconnected', () => {
      log.info('disconnected');
    });

    await page.goto('https://v.kuaishou.com/3YIAWC');

  }
}

export default WXLiveEventListener;
